<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.mselect.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.mselect.js?"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.multiselect.js"></script>
<script type="text/javascript">
$(function(){
	$(".datepicker").datepicker({dateFormat:'yy-mm-dd',changeMonth:true});
	$("#multiselect").multiselect({height: 260, minWidth: 160});
});
</script>
<fieldset><legend>查询条件</legend>
<form method="get">
<? include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
<tr>
	<th>日期：</th>
	<td>
		<input type="text" class="datepicker" name="begin_shipped_time" value="<?=isset($_GET['begin_shipped_time'])?$_GET['begin_shipped_time']:date('Y-m-01', strtotime(date('Y-m-d',CURRENT_TIMESTAMP).' -1 month'))?>" /> to 
		<input type="text" class="datepicker" name="end_shipped_time" value="<?=isset($_GET['end_shipped_time'])?$_GET['end_shipped_time']:date('Y-m-t', strtotime(date('Y-m-d',CURRENT_TIMESTAMP).' -1 month'))?>" />
	</td>
</tr>
<tr>
	<th>操作人员</th>
	<td>
		<select name="user_id[]" multiple="multiple" id="multiselect">
		<?foreach ($user as $u):?>
		<option value="<?=$u['id']?>" <?if (isset($_GET['user_id']) && is_array($_GET['user_id']) && in_array($u['id'], $_GET['user_id'])) echo "selected='selected'"?>><?=$u['name']?></option>
		<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>周期</th>
	<td>
		<label><input name="period" type="radio" value="daily" <?=(isset($_GET['period'])&&$_GET['period']=='daily')?"checked='checked'":''?> />日报表</label>&nbsp;&nbsp;
		<label><input name="period" type="radio" value="weekly" <?=(isset($_GET['period'])&&$_GET['period']=='weekly')?"checked='checked'":''?> />周报表</label>&nbsp;&nbsp;
		<label><input name="period" type="radio" value="monthly" <?=((isset($_GET['period'])&&$_GET['period']=='monthly')||(!isset($_GET['period'])))?"checked='checked'":''?> />月报表</label>
	</td>
</tr>
<tr>
	<td><input type="hidden" name="is_search" value="1" /></td>
	<td><input type="submit" class="button" value="查询" /></td>
</tr>
</table>
</form></fieldset>
<?if (isset($_GET['is_search']) && $_GET['is_search'] && ! empty($report)):?>
<table class="list_table" width="100%">
	<tr>
		<th>日期</th>
		<th>操作人员</th>
		<th>拣货单个</th>
		<th>拣货多个</th>
		<th>拣货产品总数</th>
		<th>过机单个</th>
		<th>过机多个</th>
		<th>过机产品总数</th>
		<th>包装单个</th>
		<th>包装多个</th>
		<th>包装产品总数</th>
		<th>称重</th>
		<th>称重产品总数</th>
		<th>总计操作数</th>
		<th>总计产品数</th>
	</tr>
	<?$total['pick']=$total['picks']=$total['pick_product_quantity']=$total['print']=$total['prints']=$total['print_product_quantity']=$total['pack']=$total['packs']=$total['pack_product_quantity']=$total['weigh']=$total['weigh_product_quantity']=$total['operation']=$total['quantity']=0;?>
	<?foreach ($report as $r):?>
	<tr>
		<td title="<?=date('Y-m-d', strtotime($r['begin_time'])).'~'.date('Y-m-d', strtotime($r['end_time']))?>"><?=($_GET['period']=='daily')?date('Y-m-d', strtotime($r['begin_time'])):(($_GET['period']=='weekly')?'第'.date('W',strtotime($r['begin_time'])).'周':date('Y-m',strtotime($r['begin_time'])))?></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
	</tr>
	<?$subtotal['pick']=$subtotal['picks']=$subtotal['pick_product_quantity']=$subtotal['print']=$subtotal['prints']=$subtotal['print_product_quantity']=$subtotal['pack']=$subtotal['packs']=$subtotal['pack_product_quantity']=$subtotal['weigh']=$subtotal['weigh_product_quantity']=$subtotal['operation']=$subtotal['quantity']=0;?>
	<?foreach ($r['result'] as $k => $rr):?>
	<tr>
		<td></td>
		<td>
			<?foreach ($user as $u):?>
			<?=($u['id'] == $k) ? $u['name'] : '';?>
			<?endforeach;?>
		</td>
		<td><?=isset($rr['pick']) ? $rr['pick'] : $rr['pick']=0;?></td>
		<td><?=isset($rr['picks']) ? $rr['picks'] : $rr['picks']=0;?></td>
		<td><?=isset($rr['pick_product_quantity']) ? $rr['pick_product_quantity'] : $rr['pick_product_quantity']=0;?></td>
		<td><?=isset($rr['print']) ? $rr['print'] : $rr['print']=0;?></td>
		<td><?=isset($rr['prints']) ? $rr['prints'] : $rr['prints']=0;?></td>
		<td><?=isset($rr['print_product_quantity']) ? $rr['print_product_quantity'] : $rr['print_product_quantity']=0;?></td>
		<td><?=isset($rr['pack']) ? $rr['pack'] : $rr['pack']=0;?></td>
		<td><?=isset($rr['packs']) ? $rr['packs'] : $rr['packs']=0;?></td>
		<td><?=isset($rr['pack_product_quantity']) ? $rr['pack_product_quantity'] : $rr['pack_product_quantity']=0;?></td>
		<td><?=isset($rr['weigh']) ? $rr['weigh'] : $rr['weigh']=0;?></td>
		<td><?=isset($rr['weigh_product_quantity']) ? $rr['weigh_product_quantity'] : $rr['weigh_product_quantity']=0;?></td>
		<td><?=$rr['pick']+$rr['picks']+$rr['print']+$rr['prints']+$rr['pack']+$rr['packs']+$rr['weigh'];?></td>
		<td><?=$rr['pick_product_quantity']+$rr['print_product_quantity']+$rr['pack_product_quantity']+$rr['weigh_product_quantity'];?></td>
	</tr>
	<?
		$subtotal['pick'] = $subtotal['pick'] + $rr['pick'];
		$subtotal['picks'] = $subtotal['picks'] + $rr['picks'];
		$subtotal['pick_product_quantity'] = $subtotal['pick_product_quantity'] + $rr['pick_product_quantity'];
		$subtotal['print'] = $subtotal['print'] + $rr['print'];
		$subtotal['prints'] = $subtotal['prints'] + $rr['prints'];
		$subtotal['print_product_quantity'] = $subtotal['print_product_quantity'] + $rr['print_product_quantity'];
		$subtotal['pack'] = $subtotal['pack'] + $rr['pack'];
		$subtotal['packs'] = $subtotal['packs'] + $rr['packs'];
		$subtotal['pack_product_quantity'] = $subtotal['pack_product_quantity'] + $rr['pack_product_quantity'];
		$subtotal['weigh'] = $subtotal['weigh'] + $rr['weigh'];
		$subtotal['weigh_product_quantity'] = $subtotal['weigh_product_quantity'] + $rr['weigh_product_quantity'];
		$subtotal['operation'] = $subtotal['pick'] + $subtotal['picks'] + $subtotal['print'] + $subtotal['prints'] + $subtotal['pack'] + $subtotal['packs'] + $subtotal['weigh'];
		$subtotal['quantity'] = $subtotal['pick_product_quantity'] + $subtotal['pack_product_quantity'] + $subtotal['weigh_product_quantity'];
	?>
	<?endforeach;?>
	<tr>
		<td align="right" colspan="2"><b>小计：</b></td>
		<td><b><?=$subtotal['pick']?></b></td>
		<td><b><?=$subtotal['picks']?></b></td>
		<td><b><?=$subtotal['pick_product_quantity']?></b></td>
		<td><b><?=$subtotal['print']?></b></td>
		<td><b><?=$subtotal['prints']?></b></td>
		<td><b><?=$subtotal['print_product_quantity']?></b></td>
		<td><b><?=$subtotal['pack']?></b></td>
		<td><b><?=$subtotal['packs']?></b></td>
		<td><b><?=$subtotal['pack_product_quantity']?></b></td>
		<td><b><?=$subtotal['weigh']?></b></td>
		<td><b><?=$subtotal['weigh_product_quantity']?></b></td>
		<td><b><?=$subtotal['operation']?></b></td>
		<td><b><?=$subtotal['quantity']?></b></td>
	</tr>
	<?
		$total['pick'] = $total['pick'] + $subtotal['pick'];
		$total['picks'] = $total['picks'] + $subtotal['picks'];
		$total['pick_product_quantity'] = $total['pick_product_quantity'] + $subtotal['pick_product_quantity'];
		$total['print'] = $total['print'] + $subtotal['print'];
		$total['prints'] = $total['prints'] + $subtotal['prints'];
		$total['print_product_quantity'] = $total['print_product_quantity'] + $subtotal['print_product_quantity'];
		$total['pack'] = $total['pack'] + $subtotal['pack'];
		$total['packs'] = $total['packs'] + $subtotal['packs'];
		$total['pack_product_quantity'] = $total['pack_product_quantity'] + $subtotal['pack_product_quantity'];
		$total['weigh'] = $total['weigh'] + $subtotal['weigh'];
		$total['weigh_product_quantity'] = $total['weigh_product_quantity'] + $subtotal['weigh_product_quantity'];
		$total['operation'] = $total['operation'] + $subtotal['operation'];
		$total['quantity'] = $total['quantity'] + $subtotal['quantity'];
	?>
	<?endforeach;?>
	<tr>
		<td align="right" colspan="2"><b>总计：</b></td>
		<td><b><?=$total['pick']?></b></td>
		<td><b><?=$total['picks']?></b></td>
		<td><b><?=$total['pick_product_quantity']?></b></td>
		<td><b><?=$total['print']?></b></td>
		<td><b><?=$total['prints']?></b></td>
		<td><b><?=$total['print_product_quantity']?></b></td>
		<td><b><?=$total['pack']?></b></td>
		<td><b><?=$total['packs']?></b></td>
		<td><b><?=$total['pack_product_quantity']?></b></td>
		<td><b><?=$total['weigh']?></b></td>
		<td><b><?=$total['weigh_product_quantity']?></b></td>
		<td><b><?=$total['operation']?></b></td>
		<td><b><?=$total['quantity']?></b></td>
	</tr>
</table>
<?endif;?>
<?php $this->_endblock();?>